package com.example.dbDemo.service.impl;

import com.example.dbDemo.model.entity.CompanyEntity;
import com.example.dbDemo.service.CompanyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

/**
 * @author 张渠钦
 * @date 2021/7/15 15:55
 */
@Service
public class CompanyServiceImpl implements CompanyService {

    @Resource
    private DataSource dataSource;

    @Override
    public List<CompanyEntity> companies(String id) {

    try (Connection connection = dataSource.getConnection()) {
        Statement statement = connection.createStatement();

        StringBuffer sql = new StringBuffer();
        sql.append(" select * from ipi_company force index(`PRIMARY`) where id > '");
        sql.append(id);
        sql.append("'");
        sql.append(" limit 0,10");

        ResultSet resultSet = statement.executeQuery(sql.toString());
        while (resultSet.next()) {
            System.out.println(resultSet.getString(1));
            System.out.println(resultSet.getString(2));
            System.out.println(resultSet.getString(3));
            System.out.println(resultSet.getString(4));
            System.out.println(resultSet.getString(5));
            System.out.println(resultSet.getString(6));
        }
    } catch (SQLException ex) {
        ex.printStackTrace();
    }

        return null;
    }
}
